package com.controller.retrieval;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.table.distance;
import com.util.connection.ConnectionManager;

public class GaborImageRetrieveNextPage {

	private HttpServletRequest servletRequest;
    HttpServletRequest request=ServletActionContext.getRequest();  
   
    public String execute() {
    	
    	 int pageNo= Integer.parseInt((String)request.getParameter("pageNo"));
    	 Connection conn = null;
		 Statement stmt = null;
		try {
		  conn = ConnectionManager.getConnectionGabor();
          stmt = conn.createStatement();
          ServletActionContext.getRequest().getSession().setAttribute("current_gb_query", "11202");
          String max_img_id = (String) ServletActionContext.getRequest().getSession().getAttribute("current_gb_query");
          String sel_sql = "select data_im_id,distance from gb_pw_mean_std_dist where query_im_id=" +max_img_id + "  order by distance LIMIT "+ pageNo*25 + " , 25";
          ResultSet rs_img = stmt.executeQuery(sel_sql);
          ArrayList imgList = new ArrayList();
          
	      while(rs_img.next()){
	    	distance imgDistObj=new distance();
	    	imgDistObj.setData_im_id(rs_img.getString("data_im_id"));
	    	imgList.add(imgDistObj);
	       }
	      rs_img.close();
	     request.setAttribute("imgList", imgList);
	      
     } catch(SQLException se){
         se.printStackTrace();
     }catch(Exception e){
        e.printStackTrace();
     }finally{
        try{
           if(stmt!=null)
              conn.close();
        }catch(SQLException se){
        }
        try{
           if(conn!=null)
              conn.close();
        }catch(SQLException se){
           se.printStackTrace();
        }
     }
    	return "success";
    }
    
}
